package com.jsu.forum.controller.v1;

import com.jsu.forum.service.impl.CommentServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.model.common.dtos.ResponseResult;
import org.example.model.forum.dto.CommentDto;
import org.example.model.forum.dto.LikeCountDto;
import org.example.model.forum.pojo.PassageComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/web/v1/comment")
@Api(tags = "评论控制器")
public class CommentController {
    @Autowired
    private CommentServiceImpl commentService;

    @PostMapping("/get")
    @ApiOperation(value = "获取评论列表", notes = "根据评论的类型,分页信息获取评论列表")
    public ResponseResult getComments(@RequestBody CommentDto commentDto){
        return commentService.getComments(commentDto);
    }

    @PostMapping("/publish")
    @ApiOperation(value = "发布评论", notes = "发布评论")
    public ResponseResult publishComment(@RequestBody PassageComment comment){
        return commentService.publishComment(comment);
    }

    @ApiOperation(value = "删除评论", notes = "根据评论的id删除评论")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteComment(@PathVariable Integer id){
        return commentService.deleteCommnet(id);
    }

    @ApiOperation(value = "点赞评论", notes = "根据评论的id点赞评论")
    @PostMapping("/likes")
    public ResponseResult likesComment(@RequestBody LikeCountDto likeCountDto){
        return commentService.likesComment(likeCountDto);
    }

    @PostMapping("/unlikes")
    @ApiOperation(value = "取消点赞评论", notes = "根据评论的id取消点赞评论")
    public ResponseResult unlikesComment(@RequestBody LikeCountDto likeCountDto){
        return commentService.unlikesComment(likeCountDto);
    }
}
